/**
 * @filename TaskAction.java
 * @directory /src/com/tianjian/oa/task
 * @package com.tianjian.oa.task
 * @description 文件描述
 * @author 胡世君
 * @date 2013-05-07 22:28:51
 * @version v0.1
 */
package com.tianjian.oa.task;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.tianjian.common.BaseAction;
import com.tianjian.common.Criteria;
import com.tianjian.oa.task.pojos.Task;
import com.tianjian.oa.task.services.TaskService;

/**
 * @author 胡世君
 */
public class TaskAction extends BaseAction {

	private static final long serialVersionUID = -14409761586366354L;

	@Autowired
	private TaskService taskService;

	private Task task;

	private String id;

	public TaskAction() {
		super("Task");
	}

	/**
	 * 显示起始页
	 */
	 @Override
	public String index() {
		request.setAttribute("timestamp", new Timestamp(new java.util.Date().getTime()));
		request.setAttribute("sqldate", new Date(new java.util.Date().getTime()));
		return SUCCESS;
	}

	/**
	 * 显示起始页
	 */
	public String mytask() {
		request.setAttribute("timestamp", new Timestamp(new java.util.Date().getTime()));
		request.setAttribute("sqldate", new Date(new java.util.Date().getTime()));
		return SUCCESS;
	}

	/**
	 * 显示起始页
	 */
	public String alltask() {
		request.setAttribute("timestamp", new Timestamp(new java.util.Date().getTime()));
		request.setAttribute("sqldate", new Date(new java.util.Date().getTime()));
		return SUCCESS;
	}
		
	/**
	 * 查看
	 */
	@Override
	public String view() {
		return SUCCESS;
	}

	/**
	 * 获取数据
	 * @return
	 */
	 @Override
	public String get() {
		Criteria criteria = new Criteria();
		inversionCriteria(criteria);
		int total = taskService.getCount(criteria);
		List<Task> rows = taskService.getData(criteria);
		this.result.put("total", total);
		this.result.put("rows", rows);
		return JSON;
	}

	/**
	 * 添加
	 * @return
	 */
	 @Override
	public String add() {
		if (exec == null) {
			return SUCCESS;
		} else {
			int rst = taskService.add(task);
			result.put("result", rst);
			return JSON;
		}
	}

	/**
	 * 编辑
	 * @return
	 */
	 @Override
	public String edit() {
		if (exec == null) {
			return SUCCESS;
		} else {
			int rst = taskService.edit(task);
			result.put("result", rst);
			return JSON;
		}
	}

	/**
	 * 删除
	 * @return
	 */
	 @Override
	public String del() {
		int rst = taskService.del(id);
		result.put("result", rst);
		return JSON;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

}
